<template>
	<view class="app l_pages" :style="'background:' + bgdata.bg_color + ';' + skin">
		<jnavbar :PageId="0" :title="title" :bgdata="bgdata"></jnavbar>
		<scroll-view class="page_container" scroll-y><renovation v-for="(item, i) in list" :mydata="item.data" :key="i"></renovation></scroll-view>
		<uni-login ref="Login" @callback="logincallback"></uni-login>
		<tab-bar ref="tabbar"></tab-bar>
	</view>
</template>

<script>
import renovation from '@/components/renovation/index.vue';
import {mapState, mapMutations} from 'vuex';
import {setShare} from '@/common/wxJsSDK';

export default {
	onShareAppMessage() {
		// let data = this.wxSharedata;
		return this.wxShare();
	},
	data() {
		return {
			list: [],
			title: '',
			bgdata: {},
			wxSharedata: {
				title: '',
				imageUrl: '',
				content: '',
				path: ''
			}
		};
	},
	components: {
		renovation
	},
	computed: {
		...mapState({
			skin: state => state.skin,
			UserInfo: state => state.UserInfo
		})
	},
	async onLoad(e) {
		await this.$getWx;
		// #ifdef MP-WEIXIN
		wx.showShareMenu({
			withShareTicket: false,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		// #endif
		
		if (e.id) {
			this.id = e.id;
			this.custompage();
		} else {
			uni.showModal({
				content: '页面不存在！',
				showCancel: false,
				success(e) {
					uni.navigateBack();
				}
			});
		}
	},
	onPullDownRefresh() {
		this.custompage();
	},
	methods: {
		buildShare() {
			// #ifdef MP-WEIXIN
			this.wxSharedata = {
				title: this.title,
				imageUrl: '',
				content: '',
				path: 'pages/custompage/custompage?id=' + this.id + '&recommendCode=' + this.UserInfo.id
			};
			// #endif
			// #ifndef MP-WEIXIN
			let url = window.location.href;
			let index = url.indexOf('?');
			if (index != -1) {
				url = url  + '&recommendCode=' + this.UserInfo.id;
			}
			let data = {
				title: this.title,
				desc: '',
				imgUrl: '',
				link: url
			};
			setShare(data);
			// #endif
		},
		custompage() {
			let data = {
				id: this.id
			};
			this.$http('/renovation/custom', data, 'GET').then(res => {
				uni.stopPullDownRefresh();
				if (res.statusCode == 200) {
					let data = res.data;
					let configure = JSON.parse(data.msg);
					this.bgdata = configure.page_config;
					this.list = configure.list;
					if (configure.list1) {
						this.list = this.list.concat(configure.list1);
					}
					uni.setNavigationBarTitle({
						title: configure.page_data.nav_name
					});
					this.title = configure.page_data.nav_name;
				}
				// this.buildShare()
			});
		},

		logincallback() {}
	}
};
</script>

<style></style>
